﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace bigormscreensaver
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Settings settings = new Settings();

            string sSwitch = (args.Length > 0 && args[0].Length > 1) ? sSwitch = args[0].Substring(0, 2).ToLower() : "";

            if (sSwitch == "/s") // Show screensaver on every screen
            {
                ScreensaverForm mainForm = null, aForm;
                foreach (var screen in Screen.AllScreens)
                {
                    aForm = new ScreensaverForm(settings, screen.Bounds);
                    aForm.Show();
                    if (mainForm == null)
                        mainForm = aForm;
                }
                Application.Run(mainForm);
            }
            else if (sSwitch == "/c") // Configuration mode
                Application.Run(new SettingsForm(settings));
            else if (sSwitch == "/d") // Configuration mode with debug
            {
                SettingsForm mainForm = new SettingsForm(settings);
                mainForm.Show_Debug();
                Application.Run(mainForm);
            }
            else if (sSwitch == "/p") // Preview mode, attempt to get handle
            {
                string sHandle = null;
                if (args[0].Length > 3)
                    sHandle = args[0].Substring(3);
                else if (args.Length > 1)
                    sHandle = args[1];
                long lHandle;
                if (long.TryParse(sHandle, out lHandle))
                    Application.Run(new ScreensaverForm(settings, new IntPtr(lHandle)));
                else
                    Application.Run(new ScreensaverForm(settings));
            }
            else // Show app
                Application.Run(new AppForm(settings));
        }
    }
}
